<!DOCTYPE html>
<title>Test playbackRate and defaultPlaybackRate.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<video></video>
<script>
// "playbackRate" should not change when play() is called.
// "playbackRate" and "defaultPlaybackRate" should always return the last value set.
async_test(function(t) {
    var video = document.querySelector("video");

    video.oncanplaythrough = t.step_func(function() {
        video.oncanplaythrough = null;
        // checking defaults.
        assert_equals(video.playbackRate, 1);
        assert_equals(video.defaultPlaybackRate, 1);

        // setting defaultPlaybackRate.
        video.defaultPlaybackRate = 2;
        assert_equals(video.playbackRate, 1);
        assert_equals(video.defaultPlaybackRate, 2);
    });

    video.onended = t.step_func_done(function() {
        assert_equals(video.playbackRate, 1);
        assert_equals(video.defaultPlaybackRate, 2);

        // Test extreme playback rates.

        video.defaultPlaybackRate = Number.MIN_VALUE;
        assert_equals(video.defaultPlaybackRate, 2);

        video.defaultPlaybackRate = Number.MAX_VALUE;
        assert_equals(video.defaultPlaybackRate, 2);

        assert_throws_dom("NotSupportedError", function() { video.playbackRate = Number.MIN_VALUE; });
        assert_throws_dom("NotSupportedError", function() { video.playbackRate = Number.MAX_VALUE; });

        // Test non-finite playback rates.
        assert_throws_js(TypeError, function() { video.defaultPlaybackRate = -Infinity; });
        assert_throws_js(TypeError, function() { video.defaultPlaybackRate = Infinity; });
        assert_throws_js(TypeError, function() { video.defaultPlaybackRate = NaN; });

        assert_throws_js(TypeError, function() { video.playbackRate = -Infinity; });
        assert_throws_js(TypeError, function() { video.playbackRate = Infinity; });
        assert_throws_js(TypeError, function() { video.playbackRate = NaN; });
    });

    var rateChangeCount = 0;
    video.onratechange = t.step_func(function() {
        // checking rate after event.
        switch (++rateChangeCount) {
        case 1:
            assert_equals(video.playbackRate, 1);
            assert_equals(video.defaultPlaybackRate, 2);

            // setting playbackRate.
            video.playbackRate = 2;
            assert_equals(video.playbackRate, 2);
            assert_equals(video.defaultPlaybackRate, 2);
            break;
        case 2:
            assert_equals(video.playbackRate, 2);
            assert_equals(video.defaultPlaybackRate, 2);

            // beginning playback.
            video.currentTime = video.duration - 0.2;
            video.playbackRate = 1;
            assert_equals(video.playbackRate, 1);
            assert_equals(video.defaultPlaybackRate, 2);
            video.play();
            break;
        case 3:
            assert_equals(video.playbackRate, 1);
            assert_equals(video.defaultPlaybackRate, 2);
            break;
        }
    });

    video.src = "content/test.ogv";
});
</script>
